/* Copyright 2012 Ali H. Caliskan.  All rights reserved.

   This file is part of Sysmkr.

   Sysmkr is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation, either version 3 of the License, or
   (at your option) any later version.

   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   GNU General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>.
*/

package main

import (
	"fmt"
	"libmkr"
)

func main() {

	name := libmkr.GetArg(0)

	if len(name) == 0 {
		fmt.Println("warning: missing flag")
		return
	}

	libmkr.BuildEnvDirs(name)

	libmkr.FetchRecipe()
	libmkr.FetchScript(name)

	fmt.Println("info: preparing source:", name)

	vers := libmkr.GetInfoSrc(libmkr.RecipeSQLite, name)[1]

	libmkr.GetSrcFile(name, vers)

	fmt.Println("      done")

	libmkr.ExtractFile(name, vers)

	fmt.Println("      done")

	fmt.Println("info: compiling source:", name + "-" + vers)

	skip := libmkr.GetArg(1)
	path := libmkr.GetInfoSrc(libmkr.RecipeSQLite, name)[4]

	libmkr.RunScript(name, vers, skip, path)

	fmt.Println("      done")

	fmt.Println("info: creating package:", name + "-" + vers)

	grp := libmkr.GetInfoSrc(libmkr.RecipeSQLite, name)[2]
	sys := libmkr.GetInfoSrc(libmkr.RecipeSQLite, name)[5]

	libmkr.CompressSource(name, vers, grp, sys)
	libmkr.CleanBuildEnv(name)

	fmt.Println("      done")
}
